/**
 * Beijing Jiaotong University
 * Copyright (c) 1896-2016 All Rights Reserved.
 */
package org.hh.ws.invoker.mq.client.impl;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;

import org.hh.ws.invoker.mq.client.UserMessageReceiverClient;
import org.myws.dao.mybatis.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.JmsUtils;
import org.springframework.stereotype.Service;

/**
 * User消息接收者的实现类
 * @author HuHui
 * @version $Id: UserMessageReceiverClientImpl.java, v 0.1 2016年5月12日 下午10:18:46 HuHui Exp $
 */
@Service
public class UserMessageReceiverClientImpl implements UserMessageReceiverClient {

    private static final Logger log = LoggerFactory.getLogger(UserMessageReceiverClientImpl.class);

    @Resource
    private JmsTemplate         jmsTemplate;

    @Override
    public User getMessage() {
        log.info("UserMessageReceiverClientImpl开始接收消息");
        try {
            ObjectMessage receivedMessage = (ObjectMessage) jmsTemplate.receive();
            log.info("接收的消息为:{}", receivedMessage);
            return (User) receivedMessage.getObject();
        } catch (JMSException e) {
            log.error("UserMessageReceiverClientImpl接收消息异常", e);
            throw JmsUtils.convertJmsAccessException(e);
        }
    }

}
